//package data;
//
//
//import com.xhive.XhiveDriverFactory;
//import com.xhive.core.interfaces.XhiveDatabaseIf;
//import com.xhive.core.interfaces.XhiveSessionIf;
//import com.xhive.core.interfaces.XhiveDriverIf;
//import com.xhive.dom.interfaces.XhiveElementIf;
//import com.xhive.dom.interfaces.XhiveLibraryIf;
//import com.xhive.dom.interfaces.XhiveCatalogIf;
//import com.xhive.dom.interfaces.XhiveNodeIf;
//import com.xhive.index.interfaces.XhiveIndexIf;
//import com.xhive.index.interfaces.XhiveIndexListIf;
//import com.xhive.query.interfaces.XhiveXQueryValueIf;
//
//import java.io.BufferedReader;
//import java.io.BufferedWriter;
//import java.io.File;
//import java.io.FileReader;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.util.*;
//
//import concepts.PConcept;
//
//import com.xhive.util.interfaces.IterableIterator;
//
//import org.w3c.dom.Document;
//import org.w3c.dom.ls.LSParser;
////import org.w3c.dom.as.ASModel;
//
//
//public class XDB {
//
//	ArrayList<String> author = new ArrayList<String>();
//	ArrayList<String> affiliation = new ArrayList<String>();
//	ArrayList<String> country = new ArrayList<String>();
//	  
//	String administratorName = "Administrator";
//	String administratorPassword = "123456";
//	XhiveDriverIf dr;
//	XhiveSessionIf session;
//	XhiveLibraryIf root;
//	String doc;
//	public static final int MAX_LINE = 100;
//	
//	public XDB(){
//		
//	}
//
//	public void openDB(String dbName, String fileName){
//		XhiveDriverIf driver = XhiveDriverFactory.getDriver("xhive://localhost:1235");
//	    driver.init();
//	    dr=driver;
//	    XhiveSessionIf session = driver.createSession();
//	    this.session = session;
//	    session.connect(administratorName, administratorPassword, dbName);
//        session.begin();
//        // get a handle to the database
//        XhiveDatabaseIf db = session.getDatabase();
//        System.out.println("Opening database: "+db.getName());
//        //create a new lib
//        XhiveLibraryIf rootLibrary = db.getRoot();
//        this.root = rootLibrary;
//        XhiveLibraryIf dblplib = rootLibrary.createLibrary();
//        String uri = (new File(fileName)).toURI().toString();
//        System.out.println("Begin parsing "+uri);
//        //XhiveCatalogIf cat = dblplib.getCatalog();
//        /*for (ASModel asModel : cat.getASModels(true)) {
//	          System.out.println(" asModel = " + asModel.getLocation());
//	        }*/
//        //create the parser for XML file
//        LSParser parser = dblplib.createLSParser();
//        parser.getDomConfig().setParameter("namespace-declarations", Boolean.FALSE);
//        //validate the dblp xml w.r.t. its DTD, with header <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE dblp SYSTEM "dblp.dtd">
//        parser.getDomConfig().setParameter("validate", Boolean.TRUE);
//        Document document = parser.parseURI(new File(fileName).toURI().toString());
//        // store the doc
//        System.out.println("Store the document ...");
//        dblplib.appendChild(document);
//        //now document == dblplib.getChildren.next();
//        System.out.println("Creating indexes ... ");
//        //create element name index
//        XhiveIndexListIf indexList = dblplib.getIndexList();
//        String[] selections = {"author", "title", "year", "booktitle"};
//        XhiveIndexIf index1 = indexList.addElementNameIndex("myindex", selections);
//        //XhiveIndexIf index1 = indexList.addValueIndex("value_index1", null, "year", null, null);
//        XhiveIndexIf index2 = indexList.addPathValueIndex("path_index", "//inproceedings[year]", XhiveIndexIf.NO_OPTIONS);
//        System.out.println("Creating indexes done! ");
//        /*Iterator<Object> keyIter = index2.getKeys();
//        while (keyIter.hasNext()) {
//          String key = (String)keyIter.next();
//          System.out.println("index:"+key);
//        }*/
//
//        System.out.println("End parsing\n");
//        String docLocation = dblplib.getChildren().next().getBaseURI();
//        this.doc = docLocation;
//	}
//	
//	
//	public void runXQuery(String doc, String xq, BufferedWriter out) throws IOException{
//		long start = System.currentTimeMillis();
//		IterableIterator<? extends XhiveXQueryValueIf> result = this.root.executeXQuery(xq);
//	    //System.out.println("any entry:"+result.hasNext());
//	    // Process the results
//	    while (result.hasNext()) {
//	      // Get the next value from the result sequence
//	      XhiveXQueryValueIf value = result.next();
//	      XhiveNodeIf pub = (XhiveNodeIf)value.asNode();
//	      String title= pub.getChildElementsNS(null, "title").next().getTextContent();
//	      String year= pub.getChildElementsNS(null, "year").next().getTextContent();
//	      String venue = pub.getChildElementsNS(null, "booktitle").next().getTextContent();
//	      String s = title+"\t"+year+"\t"+venue+"\t";
//	      //HashSet<String> authors = new HashSet<String>();
//	      for(XhiveElementIf e: pub.getChildElementsNS(null, "author")){
//	    	  String au =e.getTextContent();
//	    	  s += "\t" + au; 	  
//	    	  //authors.add(au);
//	    	  //System.out.println("author:"+au);
//	      }
//	      out.write(s);
//	      out.newLine();  
//	      // Print this value
//	      //System.out.println("title: "+title);
//	      //System.out.println("year: "+year);
//	      //System.out.println("Venue: "+venue);
//	      //System.out.println("------");
//	    }
//	    System.out.print(" time (s): "+ (System.currentTimeMillis()-start)/1000+"\n");
//
//	}
//	
//	public void commit(){
//		this.session.commit();
//	}
//	public void closeDB(){
//        if (this.session.isOpen()) {
//	      session.rollback();
//	    }
//	    if (session.isConnected()) {
//	      session.disconnect();
//	    }
//	        dr.close();
//	}
//
//	/*
//	 * Given an author name, find his/er publication details in dblp
//	 */
//	public String findAuthor(String name){
//		String xq = 
//		"for $i in document('"+this.doc+"')//inproceedings[author='"+name+"'] \n"
//		//"for $i in document('"+this.doc+"')//inproceedings \n"
//        //+ "where $i/year >1995 \n"
//        + "return $i";
//		return xq;
//	}
//	
//	//get author's pubs from year1 to year2 (both inclusive)
//	public String findAuthor(String name, int year1, int year2){
//		String xq = 
//		"for $i in document('"+this.doc+"')//inproceedings[author='"+name+"'] \n"
//		//"for $i in document('"+this.doc+"')//inproceedings \n"
//        + "where $i/year >= "+year1+" and $i/year<="+year2+"\n"
//        + "return $i";
//		return xq;
//	}
//	
//	  public static void main(String[] args) {
//		  //first populate the IJCAR members' info
//		  try{
//		  XDB xdb =new XDB();
//		  xdb.getIJCAR("IJCAR2010");
//		  //System.out.println("here");
//		  xdb.openDB("DBLP", "kdd.xml");
//		  int i=1;
//	    FileWriter fstream = new FileWriter("pub.txt");
//        BufferedWriter out = new BufferedWriter(fstream);
//		  for(String au:xdb.author){
//			  //for each famous member, get all their proceedings publications in the last 10 years
//			  String xq = xdb.findAuthor(au, 2000, 2009);
//			  try{
//				  System.out.print("Query "+i+++" processing ...");
//			  xdb.runXQuery(xdb.doc, xq, out);
//			  }catch(IOException e){
//				  e.printStackTrace();
//			  }
//			  //System.out.println(au);
//		  }
//		  xdb.commit();
//		  out.close();
//		  xdb.closeDB();
//		  }catch(IOException e){
//			  e.printStackTrace();
//		  }
//	  }
//	  
//	  public HashSet<PConcept> getListOfCountryConcept(){
//		  HashSet<PConcept> cs = new HashSet<PConcept>();
//		  if(this.country.size()<1){
//			  return null;
//		  }else{
//			  for(String c:this.country){
//				  cs.add(new PConcept(c));
//			  }
//		  }
//		  return cs;
//	  }
//	  
//	  
//	  public void getIJCAR(String file){
//		//get a list of authors with their affiliation and country in IJCAR2010
//
//		try{
//			BufferedReader in = new BufferedReader(new FileReader(file));
//		    String strLine;
//		    int i = 0;
//		    while ((strLine = in.readLine()) != null)   {
//		        // no empty lines as input
//		    	if (!strLine.trim().equals("")){
//		    		author.add(i, strLine.split(",")[0].trim());
//		    		affiliation.add(i, strLine.split(",")[1].trim());
//		    		country.add(i, strLine.split(",")[2].trim());
//		    		//System.out.println(author.get(i)+":"+affiliation.get(i)+":"+country.get(i));
//		    	}
//		    	if(++i == MAX_LINE){
//		    		System.out.println("Maximum lines parsed: increase the size of arrays.");
//		    		break;
//		    	}
//		    }
//		}catch(IOException e){
//			e.printStackTrace();
//		}
//	  }
//	  
//
//	
//}
